<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="开户银行" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bankAccountName">
              <a-input v-model="model.bankAccountName" placeholder="请输入开户银行"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="银行账号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bankAccountNum">
              <a-input v-model="model.bankAccountNum" placeholder="请输入银行账号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="营业执照" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="certificate">
              <j-image-upload isMultiple v-model="model.certificate"></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="其他资质" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="otherCertificates">
              <j-image-upload isMultiple v-model="model.otherCertificates"></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item
              label="资质认证状态：0-未认证 1-认证中 2-已认证 3-认证驳回"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              prop="certificateAuditStatus"
            >
              <j-dict-select-tag
                type="list"
                v-model="model.certificateAuditStatus"
                dictCode="certificate_audit_status"
                placeholder="请选择资质认证状态：0-未认证 1-认证中 2-已认证 3-认证驳回"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审核状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditStatus">
              <j-dict-select-tag
                type="list"
                v-model="model.auditStatus"
                dictCode="audit_status"
                placeholder="请选择审核状态"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审批意见" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditComments">
              <a-textarea v-model="model.auditComments" rows="4" placeholder="请输入审批意见"></a-textarea>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="审核人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="auditUsername">
              <a-input v-model="model.auditUsername" placeholder="请输入审核人"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
import { mapActions } from 'vuex'

export default {
  name: 'HTCertificateAuditForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {
        accountType: 3,
        certificateAuditStatus: 0,
        channel: 2,
        auditStatus: 0,
        isLocked: 0
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      validatorRules: {
        // bankAccountName: [{ required: true, message: '请输入开户银行' }],
        // bankAccountNum: [{ required: true, message: '请输入银行账号' }],
        // certificate: [{ required: true, message: '请上传资质文件' }]
      },
      url: {
        add: '/account/hTMerchant/add',
        edit: '/account/hTMerchant/edit',
        queryById: '/account/hTMerchant/queryById'
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    submitForm() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = '/account/certificateAudit'
          let method = 'post'
          httpAction(httpurl, this.model, method)
            .then(res => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
            })
        }
      })
    }
  }
}
</script>

